package cn.com.nou.common.utils;

import cn.com.nou.common.NouException;
import cn.com.nou.common.annotation.NouCodelist;
import cn.com.nou.common.constant.NouConstants;
//import io.jsonwebtoken.Jwts;
//import io.jsonwebtoken.security.Keys;

import javax.servlet.http.HttpServletRequest;
import java.security.Key;

/**
 * cas utils
 *
 * @author lixuefeng
 */
public class CasUtils {

//    public static String getUserId(String token) {
//        Key key = Keys.hmacShaKeyFor("^n0userv1cen0userv1cen0userv1ce$".getBytes());
//        return Jwts.parser().setSigningKey(key).parseClaimsJws(token).getBody().get("user", String.class);
//    }

//    public static String getUserId(HttpServletRequest request) {
//        String authorization = request.getHeader(NouConstants.ANTHORIZATION_HEADER);
//        String token = request.getParameter(NouConstants.TOKEN_FIELD);
//        if (authorization == null && token == null) {
//            throw new NouException("缺少Token");
//        }
//        try {
//            if (authorization != null) {
//                token = authorization.substring(NouConstants.BEARER_TOKEN_TYPE.length() + 1);
//            }
//            Key key = Keys.hmacShaKeyFor("^n0userv1cen0userv1cen0userv1ce$".getBytes());
//            return Jwts.parser().setSigningKey(key).parseClaimsJws(token).getBody().get("user", String.class);
//        } catch (Exception e) {
//            throw new NouException("Token不合法");
//        }
//    }
}
